﻿@model Amazon.Checkout.ViewModels.PromotionListViewModel

@{ Layout.Title = T("Manage Promotions").ToString(); }

@Html.ValidationSummary()

@using (Html.BeginFormAntiForgeryPost())
{   
    <div class="manage">@Html.ActionLink(T("Create New Promotion").ToString(), "New", new { }, new { @class = "button primaryAction" })</div>
    
    <fieldset>
        <table class="items" summary="@T("List of available promotions.")">
            <colgroup>
                <col id="Col1" />
                <col id="Col2" />
                <col id="Col3" />
                <col id="Col4" />
                <col id="Col5" />
            </colgroup>
            <thead>
                <tr>
                    <th scope="col">&nbsp;&darr;</th>
                    <th scope="col">@T("Promotion Code")</th>
                    <th scope="col">@T("Promotion Type")</th>
                    <th scope="col">@T("Amount")</th>
                    <th scope="col">@T("Actions")</th>
                </tr>
            </thead>
            
            @if (Model.Promotions.Any())
            {    
                foreach (var promotion in Model.Promotions)
                {
                    <tr>
                        <td><input type="checkbox" value="true" name="@T("Checkbox.{0}", promotion.Id)"/></td>                
                        <td>
                            @Html.ActionLink(@promotion.PromotionCode, "Edit", new { promotionId = @promotion.Id })
                        </td>
                        <td>@(promotion.PromotionType == "DiscountRate" ? "Discount Rate" : "Fixed Amount Discount")</td>
                        <td>
                            @if (promotion.PromotionType == "DiscountRate") 
                            {
                                @string.Format("{0:0.000000}", promotion.DiscountRate)
                            }
                            else 
                            {
                                @string.Format("{0:0.00}", promotion.FixedAmountDiscount)
                            }
                        </td>
                        <td>
                                @Html.ActionLink("Edit", "Edit", new { promotionId = @promotion.Id }) |
                                @Html.ActionLink("Delete", "Delete", new { promotionId = @promotion.Id }) 
                        </td>
                    </tr>
                }
            }
            else
            {
                <tr class="no-records">
                    <td colspan="5">@T("There are no promotions created.")</td>
                </tr>   
            }
        </table>
    </fieldset>
}
